www.gusucode.com > 用matlab gui 实现界面互相切换功能 给你带来新的方法 创建不同类型的界面源码程序 > 用matlab gui 实现界面互相切换功能 给你带来新的方法 创建不同类型的界面源码程序/drawtab.m

    function hb = drawtab(pos,siz,name,N,col,totalTabs)
% drawtab - draws a box with a tab, where the lower left corner
% is at position "pos" and the size of the main frame is
% specified in "size". "N" specifies the tab number and "name"
% specifies the title and "col" is the color of the tab. totalTabs
% is the total number of tabs.
%
% hb = drawtab(pos,siz,name,N,col,totalTabs)
%
% DRAWTAB is part of the TAB-TOOL, consisting of two functions
% DRAWTAB and HITTAB. These two functions allow the creation of tab
% panels within Matlab. To build the "inside" of each tab you only
% have to write one function for each tab panel and store all the
% handles in the tab's userdata.
  
% Dirk Tenne 
% CoDE (Control Dynamics and Estimation)
% web:      "http://code.eng.buffalo.edu"
% created:  "05/29/2002"
% modified: "December 12. 2002"
%
  if nargin < 6
    totalTabs = 4;
    if nargin < 5
      col = [1 0 0];
      if nargin < 4
	N = 1;
	if nargin < 3
	  name = 'untitled';
	end
      end
    end
  end

  siz = siz(:);
  
  w = siz(1);
  h = siz(2);
  wb = w*0.01;              % space between the tabs
  wN = (w-N*wb)/totalTabs;    % dividing into equal tabs
  hN = h*0.1;               % tab height, 10% of total height
  
  x = diag(pos)*ones(2,9);
  dx = zeros(2,9);          % lower left corner
  dx(1,2) = w;              % lower right corner
  dx(:,3) = siz;            % upper right corner
  dx(1,4) = wN*N+(N-1)*wb;  % lower right of the tab
  dx(2,4) = h;              %        "-"
  dx(1,5) = dx(1,4);        % upper right of the tab 
  dx(2,5) = h + hN;         %        "-"
  dx(1,6) = (N-1)*(wN+wb);  % upper left of the tab
  dx(2,6) = dx(2,5);        %        "-"
  dx(1,7) = dx(1,6);        % lower left of the tab
  dx(2,7) = dx(2,4);        %        "-"
  dx(2,8) = dx(2,7);        % upper left corner
  
  x = x + dx;
  
  h = patch(x(1,:),x(2,:),col);
  %hl = line(x(1,[3:9]),x(2,[3:9]),'color',[1 1 1]);
  hl = line([x(1,[3:4]), NaN, x(1,5:9)],[x(2,[3:4]), NaN, x(2,5:9)],'color',[1 1 1]);
  ht = text(x(1,7)+wb,x(2,7)+3*wb,name);
  set(ht,'Color',[0 0 1]);
  children.tab = [hl ht h];
  children.inp = [];
  children.matrix = [];
  set(h,'UserData',children); % set the children of that tab
  set(ht,'UserData',h);       % set the parent tab

  set(ht,'ButtonDownFcn','hittab(''stop'')')
  
  if nargout > 0
   hb = h;
  end